#include <iostream>
#include <chrono>
#include "inp.h"
#include "declaration.h"
#include "grid.h"
#include "flow.h"
#include <CL/cl.h>
// #include "../../include/"
using namespace std;
using namespace std::chrono;
// using namespace inp;

int main()
{
    
    auto time1 = steady_clock::now();

    // cl_device_type device_type = CL_DEVICE_TYPE_CPU;

    // cl_context context = 0;
    // cl_command_queue command_queue = 0;
    // cl_program program = 0;
    // cl_device_id device_id;
    // pair<cl_kernel*, int> kernel_list{NULL, 0};

    // context = CreateContext(device_type);
    // command_queue = CreateCommandQueue(context, &device_id);
    // program = CreateProgram(context, device_id, "mkernel.cl");
    // kernel_list = CreateKernel(program);

    // OpenclObj clobj;
    // clobj.GetPlatformID(2);
    // clobj.CreateContextFromType(device_type);
    // clobj.CreateCommandQueue();
    // clobj.CreateProgram("function.cl", options.c_str());
    // clobj.CreateKernelsInProgram();

    // 输出输入参数
    confirm();
    Grid grd;
    // 读入网格文件
    grd.rgrid(inp::fngrid);
    // cout << "1\n";
    // 计算体积
    grd.inigrid();
    // cout << "2\n";
    flow laval;
    // 开辟内存空间 初始化 opencl
    laval.iniMemory(grd.imax);
    // 初始化流场
    laval.iniFlow(grd);
    // cout << "3\n";
    laval.bcond(grd.area, grd.ib2);
    size_t step{0};
    double drho{0.0};
    do{
        laval.solver(grd, drho);
        ++step;
    }while((step!=inp::maxiter) && (drho > inp::convtol));

    OutPut(laval, grd);
    // inp::convergence_file.close();

    auto time2 = steady_clock::now();
    auto duration1 = duration_cast<duration<double>>(time2-time1);
    cout << "duration time = " << duration1.count() << "\n";

    return 0;
}